/**
 * @(#)CompteBancaire.java
 *Stub
 *
 *
 * @author S.ESTEVANE
 * @version 1.1.0 2011/12/12
 */
import java.io.Serializable;
import java.util.*;

public class CompteBancaire implements Serializable {

	private static final long serialVersionUID = -2062994542717559274L;

private float m_solde;
private Titulaire m_titulaire;
private Banque m_banque;
protected LinkedHashMap<Long, OperationBancaire> m_pOperation;

	public float getSoldeCompte() {
			return m_solde;
		}

	public CompteBancaire(final Banque b, Titulaire titulaire) {

		m_titulaire = titulaire;
		m_banque = b;
		m_pOperation = new LinkedHashMap<Long, OperationBancaire>();
}
	public CompteBancaire(){

		m_titulaire = new Titulaire();
		m_solde = 0;
		m_pOperation= new LinkedHashMap<Long, OperationBancaire>();
		}

	public float executer(OperationBancaire type) {

		if(type.getType() == 'R')
			this.sub(type.getMontant());

		if(type.getType() == 'V' || type.getType() == 'I')
			this.add(type.getMontant());

		m_pOperation.put(type.getNumero(), type);
		return m_solde;

	}

		protected void sub(float montant) {
		m_solde -= montant;
	}

	protected void add(float montant) {
		m_solde += montant;
	}

	public Titulaire getTitulaireCompte() {
		return m_titulaire;
}

	public boolean equals(Object obj){
		return true;
}
	public String getIdentiteTitulaire() {
		return m_titulaire.getNom() + " " + m_titulaire.getPrenom();
	}

	public int  getNombreOperations() {
		return m_pOperation.size();
	}

	public String getDateDerniereOperation(){
		if(m_pOperation.size() == 0)
			return "0";
long base = 0;

		for (long it : m_pOperation.keySet())
			if (it > base)
				base = it;

		return m_pOperation.get(base).getDate();

	}

	public String getAdresseTitulaire() {
		return m_titulaire.getAdresse();
	}

	public void setAdresse(final String newAdresse) throws IPException {
		m_titulaire.setAdresse(newAdresse);
	}
}